package com.cn.algorithm.two.union;

public class UnionFind_QU_S extends UnionFind_QU{

    int[] size;

    public UnionFind_QU_S(int capacity) {
        super(capacity);
        size = new int[capacity];
        for (int i = 0; i < size.length; i++) {
            size[i] = 1;
        }
    }

    @Override
    void union(int v1, int v2) {
        int k1 = find(v1);
        int k2 = find(v2);
        if (k1 == k2) {
            return;
        }
        if (size[k1] > size[k2]) {
            parent[k2] = k1;
            size[k1] += size[k2];
        } else {
            parent[k1] = k2;
            size[k2] += size[k1];
        }
    }
}
